﻿using System;
using Config;

namespace Utils
{
    public class UserUtils
    {
        /// <summary>
        /// Kiểm tra login chưa
        /// </summary>
        public static bool IsLogin
        {
            get
            {
                return !((SessionHelper.GetSession(Constants.COOKIE_USER_ID) == string.Empty)
                    || (SessionHelper.GetSession(Constants.COOKIE_USER_USERNAME) == string.Empty)
                    || (SessionHelper.GetSession(Constants.COOKIE_USER_FULL_NAME) == string.Empty));
            }
        }


        /// <summary>
        /// Lấy UserID 
        /// </summary>
        public static int AccountId
        {
            get
            {
                try
                {
                    return Convert.ToInt32(SessionHelper.GetSession(Constants.COOKIE_USER_ID));
                }
                catch { }
                return -1;
            }
            set
            {
                SessionHelper.SetSession(Constants.COOKIE_USER_ID, value.ToString());
            }
        }

        /// <summary>
        /// Lấy TypeAccount 
        /// </summary>
        public static int TypeAccount
        {
            get
            {
                try
                {
                    return Convert.ToInt32(SessionHelper.GetSession(Constants.COOKIE_USER_TYPE));
                }
                catch { }
                return -1;
            }
            set
            {
                SessionHelper.SetSession(Constants.COOKIE_USER_TYPE, value.ToString());
            }
        }

        /// <summary>
        /// Lấy UserName của Admin
        /// </summary>
        public static string UserName
        {
            get
            {
                try
                {
                    return SessionHelper.GetSession(Constants.COOKIE_USER_USERNAME);
                }
                catch { }
                return "";
            }
            set
            {
                SessionHelper.SetSession(Constants.COOKIE_USER_USERNAME, value);
            }
        }

        /// <summary>
        /// Lấy tên đầy đủ của Admin
        /// </summary>
        public static string FullName
        {
            get
            {
                return SessionHelper.GetSession(Constants.COOKIE_USER_FULL_NAME);
            }
            set
            {
                SessionHelper.SetSession(Constants.COOKIE_USER_FULL_NAME, value);
            }
        }
        /// <summary>
        /// Lấy tên hiển thị
        /// </summary>
        public static string DisplayName
        {
            get
            {
                var val=SessionHelper.GetSession(Constants.COOKIE_USER_DISPLAY_NAME);
                if (string.IsNullOrEmpty(val))
                    return FullName;
                return val;
            }
            set
            {
                SessionHelper.SetSession(Constants.COOKIE_USER_DISPLAY_NAME, value);
            }
        }
        /// <summary>
        /// Triple7AccessToken
        /// </summary>
        public static string Triple7AccessToken
        {
            get
            {
                return SessionHelper.GetSession(Constants.COOKIE_USER_Triple7AccessToken);
            }
            set
            {
                SessionHelper.SetSession(Constants.COOKIE_USER_Triple7AccessToken, value);
            }
        }

        /// <summary>
        /// Triple7AccessToken
        /// </summary>
        public static string GoPlayAccessToken
        {
            get
            {
                return SessionHelper.GetSession(Constants.COOKIE_USER_GoPlayAccessToken);
            }
            set
            {
                SessionHelper.SetSession(Constants.COOKIE_USER_GoPlayAccessToken, value);
            }
        }    

        /// <summary>
        /// Lấy IPAdress
        /// </summary>
        public static string IpAddress
        {
            get { return SessionHelper.GetSession(Constants.COOKIE_USER_IP_ADDRESS); }
            set { SessionHelper.SetSession(Constants.COOKIE_USER_IP_ADDRESS, value); }
        }

    }
}
